package com.gem.netty.service.common;

import com.gem.entity.Game;
import com.gem.enums.ClientMessageType;
import com.gem.enums.GameRoundStageType;
import com.gem.enums.MessageColorType;
import com.gem.factory.game.GameFactory;
import com.gem.netty.entity.ClientContent;
import com.gem.netty.entity.CurrentUser;
import com.gem.pipeline.BusinessProcess;
import com.gem.pipeline.ProcessContext;
import com.gem.utils.R;

/**
 * Author: Xhy
 * CreateTime: 2022-09-25 13:43
 * 校验是否是当前玩家回合service
 */
public class IsCurrentUserRoundService implements BusinessProcess<ClientContent> {

    @Override
    public void process(ProcessContext<ClientContent> context) {
        ClientContent data = context.getData();
        Game game = GameFactory.get(data.getRoomId());
        if (!data.getSendId().equals(game.getUsers().get(game.getCurrentIndex() % 4).getId())){
            context.setResult(R.error().data("color", MessageColorType.SYSTEM_MESSAGE.type).message("不是你的回合").type(ClientMessageType.ROUND_BEGAN.type));
            context.setNeedBreak(true);
        }
    }
}
